package com.molyfun.parents.activity.common.listactivity.factory;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.molyfun.parents.MFPApplication;
import com.molyfun.parents.R;
import com.molyfun.parents.activity.common.listactivity.AbstractListFactory;
import com.molyfun.parents.activity.common.listactivity.IResponse;
import com.molyfun.parents.activity.common.listactivity.viewholder.VideoRecordViewHolder;
import com.molyfun.parents.rest.bean.GetSingleLiveVideoRecordListResponse;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by william(liuchao.hit@gmail.com).
 * 我的界面-评估
 */
public class ClassRoomVideoRecordFactory extends AbstractListFactory<GetSingleLiveVideoRecordListResponse.SingleLiveVideoRecordBean> {

    private String mTeamId;

    public ClassRoomVideoRecordFactory(String teamId){
        mTeamId = teamId;
    }

    @Override
    public int getTitle() {
        return R.string.activity_title_classroom_video_record;
    }

    @Override
    public void getDataList(int pageNum,final IResponse responseCallback) {


        Call<GetSingleLiveVideoRecordListResponse> call = MFPApplication.getInstance().getRestClient().getLiveRecordList(mTeamId, pageNum);
        call.enqueue(new Callback<GetSingleLiveVideoRecordListResponse>() {
            @Override
            public void onResponse(Call<GetSingleLiveVideoRecordListResponse> call, Response<GetSingleLiveVideoRecordListResponse> response) {
                if (response.body() != null && response.body().getData() != null) {
                    responseCallback.onResponse(response.body().getData());

                }
            }

            @Override
            public void onFailure(Call<GetSingleLiveVideoRecordListResponse> call, Throwable t) {
            }
        });

    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(ViewGroup parent, int viewType) {
        return new VideoRecordViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.layout_class_video_record_cell, parent, false));
    }

    @Override
    public void bindViewHolder(final Context context, final GetSingleLiveVideoRecordListResponse.SingleLiveVideoRecordBean singleLiveVideoRecordBean, RecyclerView.ViewHolder holder, final int position, FragmentManager fragmentManager, int totalSize) {

        VideoRecordViewHolder videoRecordViewHolder = (VideoRecordViewHolder)holder;
//        reportListViewHolder.mTimeInterval.setText(TimeUtils.getDateByTimeMillis(trainingBean.getBegindatetime()) + "~" + TimeUtils.getDateByTimeMillis(trainingBean.getEnddatetime()));
//        reportListViewHolder.mViewPlan.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                PlanDetailActivity.startActivity(context, trainingBean.getId());
//            }
//        });
//        reportListViewHolder.mViewFeedback.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                ListActivity.startActivity(context, trainingBean.getId());
//            }
//        });

        if(position == (totalSize - 1)){
            videoRecordViewHolder.mClassVideoRecordView.initData(singleLiveVideoRecordBean, true);
        }else{
            videoRecordViewHolder.mClassVideoRecordView.initData(singleLiveVideoRecordBean);
        }
    }

    @Override
    public void deleteData(final String id,final int position) {
    }
}
